package sort;

public class Sorted2DArraySearch {

	public boolean findX(int[][] mat, int n, int m, int x) {
		// write code here

		int row = 0;
		int col = m - 1;

		while (row <= n - 1 && col >= 0) {
			if (mat[row][col] == x) {
				return true;
			} else if (mat[row][col] > x) {
				col--;
			} else {
				row++;
			}

		}
		return false;
	}
}
